home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / ExecutionContext.java < prev    next >
Text File  |  1998-10-07  |  5KB  |  201 lines

  1. package com.symantec.itools.lang;
  2.  
  3.  
  4. import java.io.IOException;
  5. import java.util.StringTokenizer;
  6. import com.symantec.itools.util.Properties;
  7. import com.symantec.itools.util.KeyNotFoundException;
  8.  
  9.  
  10. /**
  11.  * Symantec1.1WindownNT4.0x86ExecutionContextParser
  12.  * Symentec1.1Windowsx86ExecutionContextParser
  13.  * Symantec1.1x86ExecutionContextParser
  14.  * Symantec1.1ExecutionContextParser
  15.  * SymantecExecutionContextParser
  16.  *
  17.  * @author Symantec Internet Tools Division
  18.  * @version 1.0
  19.  * @since VCafe 3.0
  20.  */
  21.  
  22. public class ExecutionContext
  23. {
  24.     /**
  25.      * @since VCafe 3.0
  26.      */
  27.     protected static Class parserClass;
  28.  
  29.     /**
  30.      * @since VCafe 3.0
  31.      */
  32.     protected ExecutionContextParser parser;
  33.  
  34.     static
  35.     {
  36.         parserClass = lookupParser();
  37.     }
  38.  
  39.     protected ExecutionContext()
  40.     {
  41.     }
  42.  
  43.     public ExecutionContext(String stackTrace, int level)
  44.     {
  45.         try
  46.         {
  47.             parser = (ExecutionContextParser)parserClass.newInstance();
  48.             parser.parse(stackTrace, level);
  49.         }
  50.         catch(InstantiationException ex)
  51.         {
  52.             ex.printStackTrace();
  53.         }
  54.         catch(IllegalAccessException ex)
  55.         {
  56.             ex.printStackTrace();
  57.         }
  58.     }
  59.  
  60.     /**
  61.      * @since VCafe 3.0
  62.      */
  63.  
  64.     private static Class lookupParser()
  65.     {
  66.         return (lookupParser(AccessiblePlatform.getJavaVendor(), AccessiblePlatform.getJavaVersion(), 
  67.                              AccessiblePlatform.getOSName(), AccessiblePlatform.getOSVersion(), 
  68.                              AccessiblePlatform.getOSType(), AccessiblePlatform.getArchitecture()));
  69.     }
  70.  
  71.     private static Class lookupParser(String javaVendor, String javaVersion, String osName, String osVersion,
  72.                                       String osType, String architecture)
  73.     {
  74.         try
  75.         {
  76.             Properties properties;
  77.             Class      clazz;
  78.  
  79.             properties = new Properties("/com/symantec/itools/lang/ExecutionContext.properties");
  80.  
  81.             if(javaVendor == null)
  82.             {
  83.                 return (DefaultExecutionContextParser.class);
  84.             }
  85.  
  86.             properties = properties.getProperties(javaVendor);
  87.  
  88.             if(properties !=  null)
  89.             {
  90.                 clazz = lookupParser(properties, javaVendor + javaVersion + osName + osVersion + architecture);
  91.  
  92.                 if(clazz == null)
  93.                 {
  94.                     clazz = lookupParser(properties, javaVendor + javaVersion + osType + architecture);
  95.  
  96.                     if(clazz == null)
  97.                     {
  98.                         clazz = lookupParser(properties, javaVendor + javaVersion + architecture);
  99.  
  100.                         if(clazz == null)
  101.                         {
  102.                             clazz = lookupParser(properties, javaVendor + javaVersion);
  103.  
  104.                             if(clazz == null)
  105.                             {
  106.                                 clazz = lookupParser(properties, javaVendor);
  107.                             }
  108.                         }
  109.                     }
  110.                 }
  111.  
  112.                 if(clazz != null)
  113.                 {
  114.                     return (clazz);
  115.                 }
  116.             }
  117.         }
  118.         catch(IOException ex)
  119.         {
  120.             ex.printStackTrace();
  121.         }
  122.         catch(Throwable ex)
  123.         {
  124.             ex.printStackTrace();
  125.         }
  126.  
  127.         return (DefaultExecutionContextParser.class);
  128.     }
  129.  
  130.     private static Class lookupParser(Properties properties, String key)
  131.     {
  132.         try
  133.         {
  134.             return (properties.getClass(key));
  135.         }
  136.         catch(ClassNotFoundException ex)
  137.         {
  138.         }
  139.         catch(KeyNotFoundException ex)
  140.         {
  141.         }
  142.  
  143.         return (null);
  144.     }
  145.  
  146.     /**
  147.      * @since VCafe 3.0
  148.      */
  149.  
  150.     public String getFile()
  151.     {
  152.         return (parser.getFile());
  153.     }
  154.  
  155.     /**
  156.      * @since VCafe 3.0
  157.      */
  158.  
  159.     public String getClazz()
  160.     {
  161.         return (parser.getClazz());
  162.     }
  163.  
  164.     /**
  165.      * @since VCafe 3.0
  166.      */
  167.  
  168.     public String getMethod()
  169.     {
  170.         return (parser.getMethod());
  171.     }
  172.  
  173.     /**
  174.      * @since VCafe 3.0
  175.      */
  176.  
  177.     public int getLine()
  178.     {
  179.         return (parser.getLine());
  180.     }
  181.  
  182.     /**
  183.      * @since VCafe 3.0
  184.      */
  185.  
  186.     public String toString()
  187.     {
  188.         int    line;
  189.         String lineStr;
  190.  
  191.         line    = getLine();
  192.         lineStr = (line == -1) ? "unknown" : Integer.toString(line);
  193.  
  194.         return (getFile() + " " + getClazz() + "." + getMethod() + "(" + lineStr + ")");
  195.     }
  196.  
  197.     public static void main(String[] argv)
  198.     {
  199.         System.out.println(com.symantec.itools.lang.Debug.getExecutionContext(0));
  200.     }
  201. }